package com.sgcc.pda.mdrh.task.safe.router;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;

import com.cepri.service.yingxiao.ITTSListener;
import com.cepri.service.yingxiao.baidutts.BaiduTtsManager;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.qihoo360.replugin.RePlugin;
import com.sgcc.pda.baselibrary.utils.LogUtil;
import com.sgcc.pda.baselibrary.utils.ToastUtils;
import com.sgcc.pda.hzaidl.entity.RequestBean;
import com.sgcc.pda.lib_tools_database.bean.other.AppNoForPlan;
import com.sgcc.pda.lib_tools_database.bean.other.TicketMeasure;
import com.sgcc.pda.lib_tools_database.bean.other.TicketMeasureProcess;
import com.sgcc.pda.lib_tools_database.bean.other.TicketMeasureResult;
import com.sgcc.pda.lib_tools_database.bean.other.TicketMeasureRisk;
import com.sgcc.pda.lib_tools_database.bean.other.TicketMeasureSave;
import com.sgcc.pda.lib_tools_database.bean.other.TicketMeasureStep;
import com.sgcc.pda.lib_tools_database.bean.other.TicketState;
import com.sgcc.pda.lib_tools_database.bean.other.TicketStatePlan;
import com.sgcc.pda.lib_tools_database.bean.ticket.TicketDetail;
import com.sgcc.pda.lib_tools_database.bean.ticket.TicketDetailPlan;
import com.sgcc.pda.lib_tools_database.factory.AppNoForPlanImpl;
import com.sgcc.pda.lib_tools_database.factory.JSResultUtil;
import com.sgcc.pda.lib_tools_database.factory.KnowledgeCheck;
import com.sgcc.pda.lib_tools_database.factory.TicketCloseStateImpl;
import com.sgcc.pda.lib_tools_database.factory.TicketDetailPlanImpl;
import com.sgcc.pda.lib_tools_database.factory.TicketLocalUtil;
import com.sgcc.pda.lib_tools_database.factory.TicketMeasureImpl;
import com.sgcc.pda.lib_tools_database.factory.TicketMeasureSaveImpl;
import com.sgcc.pda.lib_tools_database.factory.TicketStateImpl;
import com.sgcc.pda.mdrh.app.ZoomApplication;
import com.sgcc.pda.mdrh.task.safe.R;
import com.sgcc.pda.mdrh.task.safe.entity.FaceParam;
import com.sgcc.pda.mdrh.task.safe.entity.MeetingResult;
import com.sgcc.pda.mdrh.task.safe.entity.MeetingVerify;
import com.sgcc.pda.mdrh.task.safe.entity.RiskBeforeResult;
import com.sgcc.pda.mdrh.task.safe.entity.RiskResult;
import com.sgcc.pda.mdrh.task.safe.entity.SafeConstant;
import com.sgcc.pda.mdrh.task.safe.entity.TicketFinishPlanVerify;
import com.sgcc.pda.mdrh.task.safe.entity.TicketFinishResult;
import com.sgcc.pda.mdrh.task.safe.entity.TicketPlanResult;
import com.sgcc.pda.mdrh.task.safe.entity.TicketPlanVerify;
import com.sgcc.pda.mdrh.task.safe.entity.TicketSaveInfo;
import com.sgcc.pda.mdrh.task.safe.entity.TicketSignInfo;
import com.sgcc.pda.mdrh.task.safe.entity.TicketVerify;
import com.sgcc.pda.mdrh.task.safe.entity.TtsEntity;
import com.sgcc.pda.mdrh.task.safe.entity.VerifyParams;
import com.sgcc.pda.mdrh.task.safe.entity.VerifyStatusEnum;
import com.sgcc.pda.mdrh.task.safe.ui.ac.MixWebViewActivity;
import com.sgcc.pda.mdrh.task.safe.ui.ac.SafeTipDialogActivity;
import com.sgcc.pda.mdrh.task.safe.ui.ac.SafeTipDialogSecondActivity;
import com.sgcc.pda.mdrh.task.safe.util.HttpUtil;
import com.sgcc.pda.mdrh.utils.ToolGson2;
import com.sgcc.pda.mdrh.zoom.router.BaseOperateRouter;
import com.sgcc.pda.model.web.request.BlockUploadFileRequest;
import com.sgcc.pda.model.web.request.PostDataCallbackRequest;
import com.sgcc.pda.sdk.entity.BaseEntity;
import com.sgcc.pda.sdk.utils.FileUtils;
import com.sgcc.pda.sdk.utils.NetWorkUtil;
import com.sgcc.pda.sdk.utils.db.SharepreferenceUtil;
import com.sgcc.pda.tools.JsonUtils;
import com.sgcc.pda.web.impl.HttpCallbackInterface;
import com.sgcc.pda.web.service.ZoomWebControler;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static com.sgcc.pda.mdrh.task.safe.entity.SafeConstant.MEETING_HAVE_FINISHED;
import static com.sgcc.pda.mdrh.task.safe.entity.SafeConstant.MEETING_NOT_FINISHED_IS_MASTER;
import static com.sgcc.pda.mdrh.task.safe.entity.SafeConstant.MEETING_NOT_FINISHED_NOT_MASTER;
import static com.sgcc.pda.mdrh.task.safe.entity.SafeConstant.MEETING_NO_DATA;
import static com.sgcc.pda.mdrh.task.safe.entity.SafeConstant.MEETING_NO_POWER;
import static com.sgcc.pda.mdrh.task.safe.entity.SafeConstant.TICKET_STATE_BREAK;
import static com.sgcc.pda.mdrh.task.safe.entity.SafeConstant.TICKET_STATE_HAVE_FINISH;
import static com.sgcc.pda.mdrh.task.safe.entity.SafeConstant.TICKET_STATE_WAIT_ALLOW;
import static com.sgcc.pda.mdrh.task.safe.entity.SafeConstant.TICKET_STATE_WAIT_FINISH;
import static com.sgcc.pda.mdrh.task.safe.entity.SafeConstant.TICKET_STATE_WAIT_SIGN;
import static com.sgcc.pda.mdrh.task.safe.entity.SafeConstant.TICKET_STATE_WAIT_SUBMIT;
import static com.sgcc.pda.mdrh.task.safe.ui.ac.MixWebViewActivity.WEB_URL;
import static com.sgcc.pda.mdrh.task.safe.ui.ac.SafeMeasureActivity.MEASURE_APPCODE;
import static com.sgcc.pda.mdrh.task.safe.ui.ac.SafeMeasureActivity.MEASURE_APPEND;
import static com.sgcc.pda.mdrh.task.safe.ui.ac.SafeMeasureActivity.MEASURE_APPNO;
import static com.sgcc.pda.mdrh.task.safe.ui.ac.SafeMeasureActivity.MEASURE_FILTER;
import static com.sgcc.pda.mdrh.task.safe.ui.ac.SafeMeasureActivity.MEASURE_ORDER;
import static com.sgcc.pda.mdrh.task.safe.ui.ac.SafeMeasureActivity.MEASURE_PLANNO;
import static com.sgcc.pda.mdrh.task.safe.ui.ac.SafeMeasureActivity.MEASURE_STEP;
import static com.sgcc.pda.mdrh.task.safe.ui.ac.SafeMeasureActivity.MEASURE_WORK;
import static com.sgcc.pda.mdrh.task.safe.ui.ac.SafeTipDialogActivity.SAFE_VERIFY_SHOW_CANCEL;
import static com.sgcc.pda.mdrh.task.safe.ui.ac.SafeTipDialogActivity.SAFE_VERITY_MESSAGE;
import static com.sgcc.pda.mdrh.task.safe.ui.ac.SafeTipDialogActivity.SAFE_VERITY_OPEN_URL;
import static com.sgcc.pda.mdrh.task.safe.ui.ac.SafeTipDialogSecondActivity.SAFE_VERITY_HINT;

/**
 * 描 述：安全管控服务路由类
 * 作 者：小卷毛  2020-12-11 13:54
 * 修改描述：增加查询字段
 * 修 改 人：
 * 修改版本：v1.2.1
 */
public class SafeRouter extends BaseOperateRouter {

    //加载离线文件
    private final boolean offlineMode = true;
    private final String onlineIP = "http://192.168.20.36:8080";

    TicketStateImpl mTicketDao;
    KnowledgeCheck mKnowledgeDao;
    TicketCloseStateImpl mTicketCloseDao;
    private ITTSListener mTTSListener;

    public SafeRouter() {
        mTicketDao = new TicketStateImpl();
        mKnowledgeDao = new KnowledgeCheck();
        mTicketCloseDao = new TicketCloseStateImpl();
    }

    @Override
    public String handleResult(
            final Context context,
            final RequestBean requestBean,
            final CompleteListener completeListener
    ) {
        String methodName = requestBean.getMethodName();
        if ("channel".equals(methodName)) {
            try {
                final PostDataCallbackRequest request = new Gson().fromJson(requestBean.getParamJson(), PostDataCallbackRequest.class);
                final String defaultSuccess = ToolGson2.getJsonStr(new BaseEntity("1", "成功"));

                // 离线操作时分离路由
                if ("loadTicketDetail".equals(request.getAction())
                        || "submitTicketPermit".equals(request.getAction())
                        || "submitMeetingEnd".equals(request.getAction())
                        || "submitRiskPoint".equals(request.getAction())
                        || "submitTicketEnd".equals(request.getAction())
                        || "saveTicketRiskResult".equals(request.getAction())
                        || "updateTicketDelay".equals(request.getAction())
                        || "getTicketFaciList".equals(request.getAction())
                        || "getLocalTicketByHand".equals(request.getAction())
                        || "getLocalMeasureByHand".equals(request.getAction())
                        || "getRealUrl".equals(request.getAction())) {
                    new OfflineRouter().handleResult(context, request, completeListener);
                    return null;
                }

                VerifyParams verifyParams = null;
                if (!"loadKnowledgeMajorCls".equals(request.getAction())
                        && !"loadMonitorPlan".equals(request.getAction())
                        && !"blockUploadFile".equals(request.getAction())
                        && !"sendMonitorData".equals(request.getAction())) {
                    verifyParams = ToolGson2.getBean(
                            request.getRequestParams(),
                            VerifyParams.class
                    );

                    String ticketWtNo = mTicketDao.findWtNoByAppNo(
                            verifyParams.getAppNo(),
                            verifyParams.getAppCode(),
                            verifyParams.getEomOrderSrc(),
                            verifyParams.getWorkTypeNo()
                    );
                    verifyParams.setWtNo(ticketWtNo);
                }

                switch (request.getAction()) {
                    // 获取工作票状态
                    case "verifyWorkTicketState":
                        if (verifyParams != null) {
                            verifyWorkTicketStateByPlan(context, verifyParams, completeListener);
                        }
                        break;
                    // 验证班前会状态
                    case "verifySiteMeetingState":
                        if (verifyParams != null) {
                            verifySiteMeetingStateByPlan(context, verifyParams, completeListener);
                        }
                        break;
                    // 验证终结工作票
                    case "applyCloseWorkTicket":
                        if (verifyParams != null) {
                            verifyCloseWorkTicketByPlan(context, verifyParams, completeListener);
                        }
                        break;
                    // 验证风险点验收
                    case "verifyRiskPointState":
                        if (verifyParams != null) {
                            handleNewRisk(context, verifyParams.getAppNo(), verifyParams, completeListener);
                        }
                        break;
                    // 跳转步骤及风险点(知识库)
                    case "gotoKnowledgeBase":
                        if (verifyParams != null) {
                            final String appNo = verifyParams.getAppNo();
                            final String planNo = verifyParams.getPlanDetNo();
                            final String appCode = verifyParams.getAppCode();
                            final String eomOrderSrc = verifyParams.getEomOrderSrc();
                            final String workTypeNo = verifyParams.getWorkTypeNo();
                            final String voicePlayer = verifyParams.getVoicePlayer();
                            final String isFilter = verifyParams.getIsFilter();
                            final String isShowAppend = verifyParams.getIsShowAppend();
                            final List<String> procNo = verifyParams.getProcNo();

                            // 查询本地工作票编号
                            String wtNo = new AppNoForPlanImpl()
                                    .getWtNo(appNo, planNo, appCode, eomOrderSrc, workTypeNo);

                            if (TextUtils.isEmpty(wtNo)) {
                                boolean isConnected = NetWorkUtil.getInstance().isConnected(context);
                                if (isConnected) {
                                    getWorkTicketStateByPlan(context, verifyParams, new IMeasureCallback() {
                                        @Override
                                        public void onSuccess() {
                                            // 查询本地工作票编号
                                            String ticketNo = new AppNoForPlanImpl()
                                                    .getWtNo(appNo, planNo, appCode, eomOrderSrc, workTypeNo);

                                            long dataSize = new TicketMeasureImpl().getSize(ticketNo);
                                            if (dataSize > 0) {
                                                completeListener.complete(1, defaultSuccess);

                                                String url = getStepAndRiskUrl(
                                                        context,
                                                        appNo,
                                                        appCode,
                                                        eomOrderSrc,
                                                        workTypeNo,
                                                        procNo,
                                                        voicePlayer,
                                                        isFilter,
                                                        isShowAppend);
                                                openWebActivity(context, url);
                                            } else {
                                                showErrorDialog(context, "获取数据失败，请稍候重试！");
                                            }
                                        }

                                        @Override
                                        public void onFailure(String msg) {
                                            if (TextUtils.isEmpty(msg)) {
                                                showErrorDialog(context, "获取工作票信息失败，请联系管理员！");
                                            } else {
                                                showErrorDialog(context, msg);
                                            }
                                        }
                                    });
                                } else {
                                    showErrorDialog(context, "获取数据失败，请检查网络状态！");
                                }
                            } else {
                                long dataSize = new TicketMeasureImpl().getSize(wtNo);
                                if (dataSize > 0) {
                                    completeListener.complete(1, defaultSuccess);

                                    String url = getStepAndRiskUrl(
                                            context,
                                            appNo,
                                            appCode,
                                            eomOrderSrc,
                                            workTypeNo,
                                            procNo,
                                            voicePlayer,
                                            isFilter,
                                            isShowAppend);
                                    openWebActivity(context, url);
                                } else {
                                    handleTicketMeasure(
                                            context,
                                            1,
                                            verifyParams,
                                            completeListener);
                                }
                            }
                        }
                        break;
                    // 跳转风险点验收(关键风险点)
                    case "gotoRiskEvidence":
                        if (verifyParams != null) {
                            final String appNo = verifyParams.getAppNo();
                            final String planNo = verifyParams.getPlanDetNo();
                            final String appCode = verifyParams.getAppCode();
                            final String eomOrderSrc = verifyParams.getEomOrderSrc();
                            final String workTypeNo = verifyParams.getWorkTypeNo();
                            final String voicePlayer = verifyParams.getVoicePlayer();
                            final String isFilter = verifyParams.getIsFilter();
                            final String isShowAppend = verifyParams.getIsShowAppend();
                            final List<String> stepNo = verifyParams.getStepNo();

                            // 查询本地工作票编号
                            String wtNo = new AppNoForPlanImpl()
                                    .getWtNo(appNo, planNo, appCode, eomOrderSrc, workTypeNo);

                            if (TextUtils.isEmpty(wtNo)) {
                                boolean isConnected = NetWorkUtil.getInstance().isConnected(context);
                                if (isConnected) {
                                    getWorkTicketStateByPlan(context, verifyParams, new IMeasureCallback() {
                                        @Override
                                        public void onSuccess() {
                                            // 查询本地工作票编号
                                            String ticketNo = new AppNoForPlanImpl()
                                                    .getWtNo(appNo, planNo, appCode, eomOrderSrc, workTypeNo);

                                            long dataSize = new TicketMeasureImpl().getSize(ticketNo);
                                            if (dataSize > 0) {
                                                completeListener.complete(1, defaultSuccess);

                                                String riskUrl = getKeyRiskPointUrl(
                                                        context,
                                                        appNo,
                                                        appCode,
                                                        eomOrderSrc,
                                                        workTypeNo,
                                                        stepNo,
                                                        voicePlayer,
                                                        isFilter,
                                                        isShowAppend);
                                                openWebActivity(context, riskUrl);
                                            } else {
                                                showErrorDialog(context, "获取数据失败，请稍候重试！");
                                            }
                                        }

                                        @Override
                                        public void onFailure(String msg) {
                                            if (TextUtils.isEmpty(msg)) {
                                                showErrorDialog(context, "获取工作票信息失败，请联系管理员！");
                                            } else {
                                                showErrorDialog(context, msg);
                                            }
                                        }
                                    });
                                } else {
                                    showErrorDialog(context, "获取数据失败，请检查网络状态！");
                                }
                            } else {
                                long dataSize = new TicketMeasureImpl().getSize(wtNo);
                                if (dataSize > 0) {
                                    completeListener.complete(1, defaultSuccess);

                                    String riskUrl = getKeyRiskPointUrl(
                                            context,
                                            appNo,
                                            appCode,
                                            eomOrderSrc,
                                            workTypeNo,
                                            stepNo,
                                            voicePlayer,
                                            isFilter,
                                            isShowAppend);
                                    openWebActivity(context, riskUrl);
                                } else {
                                    handleTicketMeasure(
                                            context,
                                            2,
                                            verifyParams,
                                            completeListener);
                                }
                            }
                        }
                        break;
                    // 跳转语音提示作业前风险点
                    case "gotoRiskTip":
                        if (verifyParams != null) {
                            final String appNo = verifyParams.getAppNo();
                            final String planNo = verifyParams.getPlanDetNo();
                            final String appCode = verifyParams.getAppCode();
                            final String eomOrderSrc = verifyParams.getEomOrderSrc();
                            final String workTypeNo = verifyParams.getWorkTypeNo();
                            final String isFilter = verifyParams.getIsFilter();
                            final String isShowAppend = verifyParams.getIsShowAppend();
                            final List<String> stepNo = verifyParams.getStepNo();

                            // 查询本地工作票编号
                            String wtNo = new AppNoForPlanImpl()
                                    .getWtNo(appNo, planNo, appCode, eomOrderSrc, workTypeNo);

                            if (TextUtils.isEmpty(wtNo)) {
                                boolean isConnected = NetWorkUtil.getInstance().isConnected(context);
                                if (isConnected) {
                                    final VerifyParams finalVerifyParams = verifyParams;
                                    getWorkTicketStateByPlan(context, verifyParams, new IMeasureCallback() {
                                        @Override
                                        public void onSuccess() {
                                            List<TicketMeasureRisk> list = new KnowledgeCheck()
                                                    .getTicketMeasureList(
                                                            appNo,
                                                            appCode,
                                                            eomOrderSrc,
                                                            workTypeNo,
                                                            planNo,
                                                            isFilter,
                                                            isShowAppend,
                                                            stepNo);

                                            if (list.size() > 0) {
                                                showBeforeDialog(
                                                        context,
                                                        finalVerifyParams,
                                                        "作业前，请查看相关安全风险防范措施！"
                                                );

                                                SafeTipDialogSecondActivity.setCompleteListener(completeListener);
                                            } else {
                                                RiskBeforeResult result = new RiskBeforeResult("1", "成功");
                                                RiskBeforeResult.VerifyDetail verifyDetail =
                                                        new RiskBeforeResult.VerifyDetail(false, "未查询到风险防范措施信息，请检查提交参数！");
                                                result.setDTS(verifyDetail);

                                                completeListener.complete(1, ToolGson2.getJsonStr(result));
                                            }
                                        }

                                        @Override
                                        public void onFailure(String msg) {
                                            RiskBeforeResult result = new RiskBeforeResult("1", "成功");
                                            RiskBeforeResult.VerifyDetail verifyDetail =
                                                    new RiskBeforeResult.VerifyDetail(false, "风险防范措施获取失败，请稍候重试！");
                                            result.setDTS(verifyDetail);

                                            completeListener.complete(1, ToolGson2.getJsonStr(result));
                                        }
                                    });
                                } else {
                                    showErrorDialog(context, "获取数据失败，请检查网络状态！");
                                }
                            } else {
                                List<TicketMeasureRisk> list = new KnowledgeCheck()
                                        .getTicketMeasureList(
                                                appNo,
                                                appCode,
                                                eomOrderSrc,
                                                workTypeNo,
                                                planNo,
                                                isFilter,
                                                isShowAppend,
                                                stepNo);

                                if (list.size() > 0) {
                                    showBeforeDialog(
                                            context,
                                            verifyParams,
                                            "作业前，请查看相关安全风险防范措施！"
                                    );

                                    SafeTipDialogSecondActivity.setCompleteListener(completeListener);
                                } else {
                                    final VerifyParams finalVerifyParams1 = verifyParams;
                                    getMeasuresByTicket(context, wtNo, new IMeasureCallback() {

                                        @Override
                                        public void onSuccess() {
                                            List<TicketMeasureRisk> innerList = new KnowledgeCheck()
                                                    .getTicketMeasureList(
                                                            appNo,
                                                            appCode,
                                                            eomOrderSrc,
                                                            workTypeNo,
                                                            planNo,
                                                            isFilter,
                                                            isShowAppend,
                                                            stepNo);

                                            if (innerList.size() > 0) {
                                                showBeforeDialog(
                                                        context,
                                                        finalVerifyParams1,
                                                        "作业前，请查看相关安全风险防范措施！"
                                                );

                                                SafeTipDialogSecondActivity.setCompleteListener(completeListener);
                                            } else {
                                                RiskBeforeResult result = new RiskBeforeResult("1", "成功");
                                                RiskBeforeResult.VerifyDetail verifyDetail =
                                                        new RiskBeforeResult.VerifyDetail(false, "未查询到风险防范措施信息，请检查提交参数！");
                                                result.setDTS(verifyDetail);

                                                completeListener.complete(1, ToolGson2.getJsonStr(result));
                                            }
                                        }

                                        @Override
                                        public void onFailure(String msg) {
                                            RiskBeforeResult result = new RiskBeforeResult("1", "成功");
                                            RiskBeforeResult.VerifyDetail verifyDetail =
                                                    new RiskBeforeResult.VerifyDetail(false, "风险防范措施获取失败，请稍候重试！");
                                            result.setDTS(verifyDetail);

                                            completeListener.complete(1, ToolGson2.getJsonStr(result));
                                        }
                                    });
                                }
                            }
                        }
                        break;
                    // 跳转知识库首页
                    case "gotoKnowledge":
                        if (verifyParams != null) {
                            completeListener.complete(1, defaultSuccess);
                            String riskUrl = getKnowledgeUrl();
                            openWebActivity(context, riskUrl);
                        }
                        break;
                    // 查询知识库专业分类列表
                    case "loadKnowledgeMajorCls":
                        String majorCls = JSResultUtil.getProfession();
                        completeListener.complete(1, majorCls);
                        break;
                    // 查询作业监控工作计划
                    case "loadMonitorPlan":
                        getMonitorPlanList(context, completeListener);
                        break;
                    // 分块上传作业监控图片
                    case "blockUploadFile":
                        BlockUploadFileRequest requestFile =
                                ToolGson2.getBean(
                                        request.getRequestParams(),
                                        BlockUploadFileRequest.class
                                );
                        ZoomWebControler.getInstance()
                                .blockUploadFile(
                                        requestFile.getFilePath(),
                                        requestFile.getSavePath(),
                                        requestFile.isDelete(),
                                        completeListener
                                );
                        break;
                    // 提交作业监控工作计划数据
                    case "sendMonitorData":
                        verifyParams = ToolGson2.getBean(request.getRequestParams(), VerifyParams.class);
                        if (verifyParams != null) {
                            sendMonitorPlanData(context, completeListener);
                        }
                        break;
                    // 查询知识库业务分类列表
                    case "loadKnowledgeBusiCls":
                        if (verifyParams != null) {
                            String busiCls = JSResultUtil.getProfessionList(verifyParams.getWorkNo());
                            completeListener.complete(1, busiCls);
                        }
                        break;
                    // 查询知识库典型经验列表
                    case "loadKnowledgeTypicalExp":
                        if (verifyParams != null) {
                            String typicalExp = JSResultUtil.getExperienceList(verifyParams.getWorkNo());
                            completeListener.complete(1, typicalExp);
                        }
                        break;
                    // 查询知识库工作程序详情信息
                    case "loadKnowledgeProcDetail":
                        if (verifyParams != null) {
                            String procDetail = JSResultUtil.getThirdDetail(verifyParams.getWorkNo());
                            completeListener.complete(1, procDetail);
                        }
                        break;
                    // 查询知识库标准视频信息
                    case "loadKnowledgeVideo":
                        if (verifyParams != null) {
                            String video = JSResultUtil.getVideoList(verifyParams.getWorkNo());
                            completeListener.complete(1, video);
                        }
                        break;
                    // 查询标准化作业步骤及风险点（工作票）
                    case "loadOperStepRiskPoint":
                        if (verifyParams != null) {
                            completeListener.complete(
                                    1,
                                    JSResultUtil.getTicketRiskList(
                                            verifyParams.getAppNo(),
                                            verifyParams.getAppCode(),
                                            verifyParams.getEomOrderSrc(),
                                            verifyParams.getWorkTypeNo(),
                                            verifyParams.getPlanDetNo(),
                                            verifyParams.getIsFilter(),
                                            verifyParams.getIsShowAppend(),
                                            verifyParams.getProcNo()
                                    )
                            );
                        }
                        break;
                    // 查询标准化作业风险点取证列表（工作票）
                    case "loadRiskPointEvid":
                        if (verifyParams != null) {
                            completeListener.complete(
                                    1,
                                    JSResultUtil.getTicketRiskEvidenceList(
                                            verifyParams.getAppNo(),
                                            verifyParams.getAppCode(),
                                            verifyParams.getEomOrderSrc(),
                                            verifyParams.getWorkTypeNo(),
                                            verifyParams.getPlanDetNo(),
                                            verifyParams.getIsFilter(),
                                            verifyParams.getIsShowAppend(),
                                            verifyParams.getStepNo()
                                    )
                            );
                        }
                        break;
                    // 查询标准化作业风险点取证记录（改）
                    case "loadRiskPointEvidRecord":
                        if (verifyParams != null) {
                            completeListener.complete(
                                    1,
                                    JSResultUtil.getTicketRiskSaveList(
                                            verifyParams.getAppNo(),
                                            verifyParams.getAppCode(),
                                            verifyParams.getEomOrderSrc(),
                                            verifyParams.getWorkTypeNo(),
                                            verifyParams.getPlanDetNo()
                                    )
                            );
                        }
                        break;
                    // 保存标准化作业风险点取证数据（改）
                    case "saveRiskPointEviRecord":
                        try {
                            TicketSaveInfo saveData = ToolGson2.getBean(
                                    request.getRequestParams(),
                                    TicketSaveInfo.class
                            );

                            if (saveData != null
                                    && saveData.getMeasures() != null) {
                                // 获取工作计划关系表
                                AppNoForPlan inner =
                                        new AppNoForPlanImpl()
                                                .getDataByAppNoWithPlanNo(
                                                        saveData.getAppNo(),
                                                        saveData.getPlanNo(),
                                                        saveData.getAppCode(),
                                                        saveData.getEomOrderSrc(),
                                                        saveData.getWorkTypeNo());

                                if (inner != null) {
                                    saveData.setAppNo(inner.getAppNo());
                                    saveData.setPlanNo(inner.getPlanNo());
                                    saveData.setWtNo(inner.getWtNo());
                                }

                                saveData.setIsChk("1");
                                for (TicketMeasureSave item : saveData.getMeasures()) {
                                    item.setAppNo(saveData.getAppNo());
                                    item.setPlanNo(saveData.getPlanNo());
                                    item.setWtNo(saveData.getWtNo());
                                    item.setWtStatus(item.getRiskPoints().isEmpty() ? "0" : "1");

                                    if (item.getRiskPoints().isEmpty()) saveData.setIsChk("0");
                                }

                                uploadTicketRisk(
                                        context,
                                        saveData.getAppNo(),
                                        saveData.getPlanNo(),
                                        saveData.getWtNo(),
                                        saveData.getIsChk(),
                                        saveData.getMeasures(),
                                        completeListener
                                );
                            } else {
                                completeListener.complete(
                                        1,
                                        ToolGson2.getJsonStr(
                                                new BaseEntity(
                                                        "0",
                                                        "数据提交格式错误！"
                                                )
                                        )
                                );
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            completeListener.complete(
                                    1,
                                    ToolGson2.getJsonStr(
                                            new BaseEntity(
                                                    "0",
                                                    "保存失败"
                                            )
                                    )
                            );
                        }
                        break;
                    // 安全管控人脸插件调用
                    case "safeFaceInvoke":
                        FaceParam faceParam = ToolGson2.getBean(request.getRequestParams(), FaceParam.class);
                        final String alias = faceParam.getAlias();
                        final String startActivity = faceParam.getStartActivity();
                        if (!TextUtils.isEmpty(alias) && !TextUtils.isEmpty(startActivity)) {
                            try {
                                // 插件是否安装
                                if (RePlugin.isPluginDexExtracted(alias)) {
                                    if (TextUtils.equals("com.sgcc.pda.faceplugin.activity.FaceRGBCloseDebugSearchActivity", startActivity)) {
                                        String userCode = SharepreferenceUtil.getUserCode(context);
                                        //先判断本地头像是否存在
                                        if (!FileUtils.faceFileIsExists(userCode)) {
                                            ToastUtils.show(ZoomApplication.getInstance(), "请先注册人脸识别");
                                            completeListener.complete(1, ToolGson2.getJsonStr(new BaseEntity("0", "请先注册人脸识别")));
                                        } else {
                                            Intent intent = RePlugin.createIntent(alias,
                                                    "com.sgcc.pda.faceplugin.activity.FaceRGBDetectActivity");
                                            intent.putExtra("userCode", userCode);
                                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                            RePlugin.startActivity(context, intent);
                                        }
                                    } else {
                                        Intent intent = RePlugin.createIntent(alias, startActivity);
                                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                        RePlugin.startActivity(context, intent);
                                    }
                                } else {
                                    ToastUtils.show(ZoomApplication.getInstance(), "该插件未安装！");
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                ToastUtils.show(ZoomApplication.getInstance(), "应用打开失败");
                            }
                        } else {
                            ToastUtils.show(ZoomApplication.getInstance(), "插件别名或者启动类名为空");
                        }
                        break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if ("baidu_yuyin".equals(methodName)) {
            final TtsEntity request = new Gson().fromJson(
                    requestBean.getParamJson(),
                    TtsEntity.class);

            switch (request.getAction()) {
                case "init": //初始化
                    BaiduTtsManager.getInstance().initNew(context);
                    break;
                case "0": //播报文本
                    BaiduTtsManager.getInstance().play(request.getData());
                    break;
                case "1": //恢复播报
                    int state = BaiduTtsManager.getInstance().getPlayState();
                    if (0 == state) {
                        BaiduTtsManager.getInstance().play(request.getData());
                    } else {
                        BaiduTtsManager.getInstance().resumeSpeaking();
                    }
                    break;
                case "2": //暂停播报
                    BaiduTtsManager.getInstance().pauseSpeaking();
                    break;
                case "-1":
                    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        @Override
                        public void run() {
                            ToastUtils.show(context, "语音未授权，请在个人中心进行授权申请");
                        }
                    });
                    break;
            }

            if (!"-1".equals(request.getAction())) {
                if (mTTSListener == null) {
                    mTTSListener = new ITTSListener() {
                        @Override
                        public void onSpeakStart() {
                            completeListener.complete(1, "onSpeakStart");
                        }

                        @Override
                        public void onSpeakPaused() {
                            completeListener.complete(1, "onSpeakPaused");
                        }

                        @Override
                        public void onSpeakResumed() {
                            completeListener.complete(1, "onSpeakResumed");
                        }

                        @Override
                        public void onCompleted() {
                            completeListener.complete(1, "onCompleted");
                        }
                    };
                }

                BaiduTtsManager.getInstance().setPlayListener(mTTSListener);
            }
        }

        return null;
    }

    /**
     * 验证工作票状态（工作计划）
     *
     * @param context  上下文
     * @param params   业务应用输入参数
     * @param listener 处理结果回调
     */
    private void verifyWorkTicketStateByPlan(
            final Context context,
            final VerifyParams params,
            final CompleteListener listener
    ) {
        boolean isConnected = NetWorkUtil.getInstance().isConnected(context);
        if (isConnected) {
            HttpUtil.getTicketStateByPlan(
                    context,
                    params.getAppNo(),
                    params.getPlanNo(),
                    params.getAppCode(),
                    params.getEomOrderSrc(),
                    params.getWorkTypeNo(),
                    new HttpCallbackInterface() {
                        @Override
                        public void httpSuccess(String result) {
                            LogUtil.e(result);
                            handleTicketByPlan(
                                    context,
                                    params.getAppNo(),
                                    params.getAppCode(),
                                    params.getEomOrderSrc(),
                                    params.getWorkTypeNo(),
                                    result,
                                    listener);
                        }

                        @Override
                        public void httpFailed(int errorCode, String errorMsg) {
                            listener.complete(
                                    1,
                                    ToolGson2.getJsonStr(
                                            new BaseEntity(
                                                    "31",
                                                    "网络请求失败！"
                                            )
                                    )
                            );
                        }
                    });
        } else {
            // 根据工单查询工作计划
            TicketDetailPlan planData =
                    new TicketDetailPlanImpl()
                            .findDataByAppNo(
                                    params.getAppNo(),
                                    params.getAppCode(),
                                    params.getWorkTypeNo(),
                                    params.getEomOrderSrc()
                            );

            if (planData == null) {
                listener.complete(
                        1,
                        ToolGson2.getJsonStr(
                                new BaseEntity(
                                        "40",
                                        "未查询到此数据记录！"
                                )
                        )
                );
            } else {
                // 查询工作票详情
                TicketDetail data =
                        new TicketLocalUtil().getTicketDetail(planData.getPARENT_ID());

                // 组装工作票状态信息
                if (data != null) {
                    ArrayList<TicketSignInfo> signList = new ArrayList<>();
                    if (data.getWT_PERSON_LIST() != null) {
                        for (TicketDetail.PersonList item : data.getWT_PERSON_LIST()) {
                            TicketSignInfo itemData = new TicketSignInfo();
                            itemData.setWtSignId(item.getTEMPORARY_HEAD_ID());
                            itemData.setWtSignName(item.getTEMPORARY_HEAD_NAME());
                            signList.add(itemData);
                        }
                    }

                    TicketVerify.VerifyDetail detail = new TicketVerify.VerifyDetail();
                    detail.setRecordId(data.getRECORD_ID());
                    detail.setWtNo(data.getWT_NO());
                    detail.setAppNo(params.getAppNo());
                    detail.setWtState(data.getWT_STATE());
                    detail.setWtType(data.getWT_TYPE());
                    detail.setWtOrgName(data.getWT_ORG_NAME());
                    detail.setWtStDate(data.getWT_ST_DATE());
                    detail.setWtEnDate(data.getWT_EN_DATE());
                    detail.setTicketSignInfo(signList);

                    TicketPlanVerify.VerifyPlanDetail planDetail = new TicketPlanVerify.VerifyPlanDetail();
                    planDetail.setAppNoExist("1");
                    planDetail.setMeetingRequire(data.getMEET_REQUIRED());
                    planDetail.setRiskRequire(data.getRISK_CHK_REQUIRED());
                    planDetail.setPlanNo(planData.getPLAN_NO());
                    planDetail.setWtExist("1");
                    planDetail.setWtDetail(detail);

                    TicketPlanVerify verify = new TicketPlanVerify();
                    verify.setRT_D("成功！");
                    verify.setRT_F("1");
                    verify.setDTS(planDetail);

                    handleTicketByPlan(
                            context,
                            params.getAppNo(),
                            params.getAppCode(),
                            params.getEomOrderSrc(),
                            params.getWorkTypeNo(),
                            ToolGson2.getJsonStr(verify),
                            listener);
                } else {
                    listener.complete(
                            1,
                            ToolGson2.getJsonStr(new BaseEntity("40", "未查询到此数据记录！"))

                    );
                }
            }
        }
    }

    /**
     * 获取工作票状态（工作计划）
     *
     * @param context 上下文
     * @param params  业务应用输入参数
     */
    private void getWorkTicketStateByPlan(
            final Context context,
            final VerifyParams params,
            final IMeasureCallback callback
    ) {
        HttpUtil.getTicketStateByPlan(
                context,
                params.getAppNo(),
                params.getPlanNo(),
                params.getAppCode(),
                params.getEomOrderSrc(),
                params.getWorkTypeNo(),
                new HttpCallbackInterface() {
                    @Override
                    public void httpSuccess(String result) {
                        // 返回给调用端的值
                        TicketPlanVerify.VerifyPlanDetail serverDetail;
                        // 解析服务器返回数据
                        TicketPlanVerify planVerify =
                                ToolGson2.getBean(result, TicketPlanVerify.class);

                        // 数据解析成功
                        if (planVerify != null) {
                            // 数据返回成功
                            if (planVerify.isSuccess()) {
                                serverDetail = planVerify.getDTS();
                                if (serverDetail != null) {
                                    // 有工作计划
                                    if (!TextUtils.isEmpty(serverDetail.getPlanNo())) {
                                        // 有工作票
                                        if ("1".equals(serverDetail.getWtExist())) {
                                            TicketVerify.VerifyDetail innerDetail = serverDetail.getWtDetail();
                                            if (innerDetail != null) {
                                                // 缓存到本地数据库
                                                TicketStatePlan ticketPlan = ToolGson2.getBean(
                                                        ToolGson2.getJsonStr(serverDetail),
                                                        TicketStatePlan.class
                                                );
                                                mTicketDao.insertData(
                                                        params.getAppNo(),
                                                        params.getAppCode(),
                                                        params.getEomOrderSrc(),
                                                        params.getWorkTypeNo(),
                                                        ticketPlan);

                                                // 获取防范措施信息缓存到本地
                                                getMeasuresByTicket(
                                                        context,
                                                        innerDetail.getWtNo(),
                                                        callback);

                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        showErrorDialog(context, "获取工作票信息失败，请联系管理员！");
                    }

                    @Override
                    public void httpFailed(int errorCode, String errorMsg) {
                        showErrorDialog(context, "获取工作票信息失败，请联系管理员！");
                    }
                });
    }

    /**
     * 验证班前会状态
     *
     * @param context  上下文
     * @param params   业务应用传入参数
     * @param listener 处理结果回调
     */
    private void verifySiteMeetingStateByPlan(
            final Context context,
            final VerifyParams params,
            final CompleteListener listener
    ) {
        // 获取工作计划和工单关系表
        AppNoForPlan planData = new AppNoForPlanImpl()
                .getDataByAppNoWithPlanNo(
                        params.getAppNo(),
                        params.getPlanDetNo(),
                        params.getAppCode(),
                        params.getEomOrderSrc(),
                        params.getWorkTypeNo()
                );

        if (planData != null
                && planData.getMeetingRequire() != null
                && "0".equals(planData.getMeetingRequire())) {
            // 从本地数据库查询工作票状态
            String state = mTicketDao.findTicketStateByplanNo(planData.getPlanNo());

            MeetingResult meetingResult = new MeetingResult("1", "成功");
            MeetingResult.VerifyDetail resultDetail =
                    new MeetingResult.VerifyDetail(true, true, state);
            meetingResult.setDTS(resultDetail);
            listener.complete(1, ToolGson2.getJsonStr(meetingResult));
        } else {
            boolean isConnected = NetWorkUtil.getInstance().isConnected(context);
            if (isConnected) {
                HttpUtil.getMeetingStateByPlan(
                        context,
                        params.getAppNo(),
                        params.getPlanNo(),
                        params.getAppCode(),
                        params.getEomOrderSrc(),
                        params.getWorkTypeNo(),
                        new HttpCallbackInterface() {
                            @Override
                            public void httpSuccess(String result) {
                                LogUtil.e(result);
                                handleMeeting(
                                        context,
                                        params.getAppNo(),
                                        params.getAppCode(),
                                        params.getEomOrderSrc(),
                                        params.getWorkTypeNo(),
                                        result,
                                        listener);
                            }

                            @Override
                            public void httpFailed(int errorCode, String errorMsg) {
                                listener.complete(
                                        1,
                                        ToolGson2.getJsonStr(
                                                new BaseEntity(
                                                        "31",
                                                        "网络请求错误"
                                                )
                                        )
                                );
                            }
                        }
                );
            } else {
                // 根据工单查询工作计划
                TicketDetailPlan planItem =
                        new TicketDetailPlanImpl()
                                .findDataByAppNo(
                                        params.getAppNo(),
                                        params.getAppCode(),
                                        params.getWorkTypeNo(),
                                        params.getEomOrderSrc()
                                );

                if (planItem == null) {
                    listener.complete(
                            1,
                            ToolGson2.getJsonStr(
                                    new BaseEntity(
                                            "40",
                                            "未查询到此数据记录"
                                    )
                            )
                    );
                } else {
                    // 查询工作票详情
                    TicketDetail data =
                            new TicketLocalUtil().getTicketDetail(planItem.getPARENT_ID());

                    // 组装班前会状态信息
                    if (data != null) {
                        ArrayList<MeetingVerify.VerifyData> meetingList = new ArrayList<>();
                        if (data.getWT_PERSON_LIST() != null) {
                            for (TicketDetail.PersonList item : data.getWT_PERSON_LIST()) {
                                MeetingVerify.VerifyData meetingItem = new MeetingVerify.VerifyData();
                                meetingItem.setRecordId(item.getRECORD_ID());
                                meetingItem.setWtHeadId(item.getTEMPORARY_HEAD_ID());
                                meetingItem.setWtHeadName(item.getTEMPORARY_HEAD_NAME());
                                meetingItem.setWtPerson(item.getWT_PERSON());
                                meetingItem.setGroupNo(item.getGROUP_NO());
                                meetingItem.setWtId(item.getWT_ID());
                                meetingItem.setIsMeeting(item.getIS_MEETING());

                                meetingList.add(meetingItem);
                            }
                        }

                        MeetingVerify.VerifyDetail detail = new MeetingVerify.VerifyDetail();
                        detail.setWtNo(data.getWT_NO());
                        detail.setWorkTypeNo(planItem.getWORK_TYPE_NO());
                        detail.setCurrentUserId(data.getWT_HEAD_ID());
                        detail.setSiteMeetings(meetingList);

                        MeetingVerify verify = new MeetingVerify();
                        verify.setRT_D("成功！");
                        verify.setRT_F("1");
                        verify.setDTS(detail);

                        handleMeeting(
                                context,
                                params.getAppNo(),
                                params.getAppCode(),
                                params.getEomOrderSrc(),
                                params.getWorkTypeNo(),
                                ToolGson2.getJsonStr(verify),
                                listener);
                    } else {
                        listener.complete(
                                1,
                                ToolGson2.getJsonStr(new BaseEntity("40", "未查询到此数据记录"))

                        );
                    }
                }
            }
        }
    }

    /**
     * 验证终结工作票
     *
     * @param context  上下文
     * @param params   参数
     * @param listener 回调
     */
    private void verifyCloseWorkTicketByPlan(
            final Context context,
            final VerifyParams params,
            final CompleteListener listener
    ) {
        boolean isConnected = NetWorkUtil.getInstance().isConnected(context);
        if (isConnected) {
            HttpUtil.applyCloseTicketCheckByPlan(
                    context,
                    params.getAppNo(),
                    params.getPlanNo(),
                    params.getAppCode(),
                    params.getEomOrderSrc(),
                    params.getWorkTypeNo(),
                    new HttpCallbackInterface() {
                        @Override
                        public void httpSuccess(String result) {
                            LogUtil.e(result);
                            handleTicketFinishByPlan(
                                    context,
                                    params.getAppNo(),
                                    params.getAppCode(),
                                    params.getEomOrderSrc(),
                                    params.getWorkTypeNo(),
                                    result,
                                    listener);
                        }

                        @Override
                        public void httpFailed(int errorCode, String errorMsg) {
                            listener.complete(
                                    1,
                                    ToolGson2.getJsonStr(
                                            new BaseEntity(
                                                    "31",
                                                    "网络请求错误"
                                            )
                                    )
                            );
                        }
                    });
        } else {
            // 根据工单查询工作票ID
            String wtId =
                    new TicketDetailPlanImpl()
                            .findIdByAppNo(
                                    params.getAppNo(),
                                    params.getAppCode(),
                                    params.getWorkTypeNo(),
                                    params.getEomOrderSrc());

            if (TextUtils.isEmpty(wtId)) {
                listener.complete(
                        1,
                        ToolGson2.getJsonStr(
                                new BaseEntity(
                                        "40",
                                        "未查询到此数据记录！"
                                )
                        )
                );
            } else {
                // 查询工作票详情
                TicketDetail data = new TicketLocalUtil().getTicketDetail(wtId);

                // 组装工作票终结状态信息
                if (data != null) {
                    TicketFinishPlanVerify.VerifyDetail detail =
                            new TicketFinishPlanVerify.VerifyDetail();

                    // 查询所有工作计划数量
                    int totalCount = new TicketDetailPlanImpl().queryCount(wtId);
                    // 查询已结束工作计划数量
                    int finishCount = new TicketDetailPlanImpl().queryFinishCount(wtId);

                    detail.setRecordId(data.getRECORD_ID());
                    detail.setWtNo(data.getWT_NO());
                    detail.setWtState(data.getWT_STATE());
                    detail.setConnectPlanCount(totalCount);
                    detail.setClosedPlanCount(finishCount);

                    TicketFinishPlanVerify verify = new TicketFinishPlanVerify();
                    verify.setRT_D("成功！");
                    verify.setRT_F("1");
                    verify.setDTS(detail);

                    handleTicketFinishByPlan(
                            context,
                            params.getAppNo(),
                            params.getAppCode(),
                            params.getEomOrderSrc(),
                            params.getWorkTypeNo(),
                            ToolGson2.getJsonStr(verify),
                            listener);
                } else {
                    listener.complete(
                            1,
                            ToolGson2.getJsonStr(
                                    new BaseEntity(
                                            "40",
                                            "未查询到此数据记录！"
                                    )
                            )
                    );
                }
            }
        }
    }

    /**
     * 作业监控工作计划列表
     *
     * @param context  上下文
     * @param listener 处理结果回调
     */
    private void getMonitorPlanList(Context context, final CompleteListener listener) {
        HttpUtil.getMonitorPlanList(context, new HttpCallbackInterface() {
            @Override
            public void httpSuccess(String result) {
                LogUtil.e(result);
                listener.complete(1, result);
            }

            @Override
            public void httpFailed(int errorCode, String errorMsg) {
                listener.complete(1, ToolGson2.getJsonStr(new BaseEntity("31", "网络请求错误")));
            }
        });
    }

    /**
     * 作业监控工作计划数据提交
     *
     * @param context  上下文
     * @param listener 处理结果回调
     */
    private void sendMonitorPlanData(Context context, final CompleteListener listener) {
        HttpUtil.sendMonitorPlanData(context, new HttpCallbackInterface() {
            @Override
            public void httpSuccess(String result) {
                LogUtil.e(result);
                listener.complete(1, result);
            }

            @Override
            public void httpFailed(int errorCode, String errorMsg) {
                listener.complete(1, ToolGson2.getJsonStr(new BaseEntity("31", "网络请求错误")));
            }
        });
    }

    /**
     * 查询工作票关联防范措施
     *
     * @param context 上下文
     * @param wtNo    工作票编号
     */
    private void getMeasuresByTicket(Context context, String wtNo, final IMeasureCallback callback) {
        HttpUtil.getMeasuresByTicket(context, wtNo, new HttpCallbackInterface() {
            @Override
            public void httpSuccess(String result) {
                try {
                    JSONObject obj = new JSONObject(result);
                    JSONArray array = obj.optJSONArray("DTS");
                    if (array != null) {
                        ArrayList<TicketMeasure> items = ToolGson2.jsonToArrayList(array.toString(), TicketMeasure.class);
                        new TicketMeasureImpl().insertList(items);
                        if (callback != null) {
                            callback.onSuccess();
                        }
                    } else {
                        if (callback != null) {
                            callback.onFailure("暂无数据");
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    if (callback != null) {
                        callback.onFailure("数据解析异常");
                    }
                }
            }

            @Override
            public void httpFailed(int errorCode, String errorMsg) {
                LogUtil.e("错误码：" + errorCode + "，错误信息：" + errorMsg);
                if (callback != null) {
                    callback.onFailure("请求防范措施失败");
                }
            }
        });
    }

    /**
     * 风险点步骤和取证跳转处理逻辑
     *
     * @param context          上下文
     * @param type             跳转类型
     * @param param            请求参数F
     * @param completeListener 回调
     */
    private void handleTicketMeasure(
            final Context context,
            final int type,
            final VerifyParams param,
            final CompleteListener completeListener
    ) {
        // 获取工作票编号
        String wtNo = new AppNoForPlanImpl()
                .getWtNo(
                        param.getAppNo(),
                        param.getPlanDetNo(),
                        param.getAppCode(),
                        param.getEomOrderSrc(),
                        param.getWorkTypeNo());

        if (!TextUtils.isEmpty(wtNo)) {
            HttpUtil.getMeasuresByTicket(context, wtNo, new HttpCallbackInterface() {
                @Override
                public void httpSuccess(String result) {
                    try {
                        JSONObject obj = new JSONObject(result);
                        JSONArray array = obj.optJSONArray("DTS");
                        if (array != null) {
                            ArrayList<TicketMeasure> items = ToolGson2.jsonToArrayList(array.toString(), TicketMeasure.class);
                            new TicketMeasureImpl().insertList(items);
                        }

                        String defaultSuccess = ToolGson2.getJsonStr(new BaseEntity("1", "成功"));
                        completeListener.complete(1, defaultSuccess);
                        switch (type) {
                            case 1:
                                String url = getStepAndRiskUrl(
                                        context,
                                        param.getAppNo(),
                                        param.getAppCode(),
                                        param.getEomOrderSrc(),
                                        param.getWorkTypeNo(),
                                        param.getProcNo(),
                                        param.getVoicePlayer(),
                                        param.getIsFilter(),
                                        param.getIsShowAppend()
                                );

                                openWebActivity(context, url);
                                break;
                            case 2:
                                String riskUrl = getKeyRiskPointUrl(
                                        context,
                                        param.getAppNo(),
                                        param.getAppCode(),
                                        param.getEomOrderSrc(),
                                        param.getWorkTypeNo(),
                                        param.getStepNo(),
                                        param.getVoicePlayer(),
                                        param.getIsFilter(),
                                        param.getIsShowAppend()
                                );

                                openWebActivity(context, riskUrl);
                                break;
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                        showErrorDialog(context, "数据解析失败，请重新尝试！");
                    }
                }

                @Override
                public void httpFailed(int errorCode, String errorMsg) {
                    LogUtil.e("错误码：" + errorCode + "，错误信息：" + errorMsg);
                    showErrorDialog(context, "风险点信息获取失败，请检查网络状态！");
                }
            });
        } else {
            showErrorDialog(context, "获取工作票信息失败，请联系管理员！");
        }
    }

    /**
     * 风险点错误提示框
     */
    private void showErrorDialog(Context context, String msg) {
        VerifyStatusEnum statusEnum = VerifyStatusEnum.KNOWLEDGE_PAGE;
        statusEnum.setMessage(msg);
        showDialog(context, statusEnum, "");
    }

    /**
     * 工作票处理逻辑（根据工作计划）
     *
     * @param context          上下文
     * @param appNo            工作编号
     * @param appCode          业务应用编码
     * @param eomOrderSrc      工单来源系统编号
     * @param workTypeNo       工单类型编号
     * @param result           服务器请求结果
     * @param completeListener 处理结果回调
     */
    private void handleTicketByPlan(
            Context context,
            String appNo,
            String appCode,
            String eomOrderSrc,
            String workTypeNo,
            String result,
            CompleteListener completeListener
    ) {
        // 返回给调用端的值
        TicketPlanResult planResult;
        TicketPlanVerify.VerifyPlanDetail serverDetail;
        TicketPlanResult.VerifyDetail resultDetail;

        // 签发人
        String signPerson = null;
        // 当前登录账号是否是签发人
        boolean isSignPerson = false;

        // 解析服务器返回数据
        TicketPlanVerify planVerify = ToolGson2.getBean(result, TicketPlanVerify.class);

        if (planVerify != null) {
            if (planVerify.isSuccess()) {
                serverDetail = planVerify.getDTS();
                planResult = new TicketPlanResult("1", "成功");
                if (serverDetail != null) {
                    if ("1".equals(serverDetail.getAppNoExist())) { //有工单
                        if (!TextUtils.isEmpty(serverDetail.getPlanNo())) {
                            if ("1".equals(serverDetail.getWtExist())) { //有工作票
                                TicketVerify.VerifyDetail innerDetail = serverDetail.getWtDetail();
                                if (innerDetail != null) {
                                    // 缓存到本地数据库
                                    TicketStatePlan ticketPlan = ToolGson2.getBean(
                                            ToolGson2.getJsonStr(serverDetail),
                                            TicketStatePlan.class
                                    );
                                    mTicketDao.insertData(
                                            appNo,
                                            appCode,
                                            eomOrderSrc,
                                            workTypeNo,
                                            ticketPlan);

                                    // 获取防范措施信息缓存到本地
                                    long dataSize = new TicketMeasureImpl().getSize(innerDetail.getWtNo());
                                    if (dataSize == 0) {
                                        getMeasuresByTicket(context, innerDetail.getWtNo(), null);
                                    }

                                    if (SafeConstant.TICKET_STATE_HAVE_FINISH.equals(innerDetail.getWtState())
                                            || TICKET_STATE_WAIT_FINISH.equals(innerDetail.getWtState())) {
                                        // 工作票已签发
                                        resultDetail = new TicketPlanResult.VerifyDetail(
                                                true,
                                                true,
                                                true,
                                                true,
                                                innerDetail.getWtState());
                                    } else {
                                        // 工作票待签发
                                        if (TICKET_STATE_WAIT_SIGN.equals(innerDetail.getWtState())) {
                                            if (innerDetail.getTicketSignInfo() != null) {
                                                List<TicketSignInfo> signInfoList =
                                                        new Gson().fromJson(
                                                                ToolGson2.getJsonStr(innerDetail.getTicketSignInfo()),
                                                                new TypeToken<List<TicketSignInfo>>() {
                                                                }.getType()
                                                        );

                                                if (!signInfoList.isEmpty()) {
                                                    StringBuilder sbStr = new StringBuilder();
                                                    String userCode = SharepreferenceUtil.getUserCode(context);
                                                    for (TicketSignInfo signInfo : signInfoList) {
                                                        //判断当前账号是否有签发权限
                                                        if (!TextUtils.isEmpty(userCode)
                                                                && userCode.equalsIgnoreCase(signInfo.getWtSignId())
                                                        ) {
                                                            isSignPerson = true;
                                                            break;
                                                        }
                                                        if (!TextUtils.isEmpty(signInfo.getWtSignName())) {
                                                            sbStr.append(signInfo.getWtSignName()).append("、");
                                                        }
                                                    }

                                                    if (sbStr.length() > 0) {
                                                        sbStr.deleteCharAt(sbStr.length() - 1);
                                                    }
                                                    signPerson = sbStr.toString();
                                                }
                                            }
                                        }
                                        resultDetail = new TicketPlanResult.VerifyDetail(
                                                false,
                                                true,
                                                true,
                                                true,
                                                innerDetail.getWtState());
                                    }
                                } else {
                                    // 无工作票信息
                                    resultDetail = new TicketPlanResult.VerifyDetail(
                                            false,
                                            true,
                                            true,
                                            false,
                                            "");
                                }
                            } else {
                                // 无工作票信息
                                resultDetail = new TicketPlanResult.VerifyDetail(
                                        false,
                                        true,
                                        true,
                                        false,
                                        "");
                            }
                        } else {
                            // 无工作计划信息
                            resultDetail = new TicketPlanResult.VerifyDetail(
                                    false,
                                    true,
                                    false,
                                    false,
                                    "");
                        }
                    } else {
                        // 无工单信息
                        resultDetail = new TicketPlanResult.VerifyDetail(
                                false,
                                false,
                                false,
                                false,
                                "");
                    }
                } else {
                    // 无工单信息
                    resultDetail = new TicketPlanResult.VerifyDetail(
                            false,
                            false,
                            false,
                            false,
                            "");
                }
            } else {
                // 服务端请求失败
                planResult = new TicketPlanResult("30", "请检查网络状态后尝试");
                completeListener.complete(1, ToolGson2.getJsonStr(planResult));
                return;
            }
        } else {
            // 数据解析异常
            planResult = new TicketPlanResult("50", "数据解析异常");
            completeListener.complete(1, ToolGson2.getJsonStr(planResult));
            return;
        }

        planResult.setDTS(resultDetail);
        completeListener.complete(1, ToolGson2.getJsonStr(planResult));

        //未检查通过时显示对话框
        if (!resultDetail.isChecked()) {
            // 有工单
            if (resultDetail.isHasAppNo()) {
                VerifyStatusEnum statusEnum = VerifyStatusEnum.getById(resultDetail.getWorkTicketState());
                String url;

                if (!resultDetail.isNeedWorkPlan()) {
                    // 无工作计划
                    url = getTaskUrl(
                            context,
                            appNo,
                            appCode,
                            eomOrderSrc,
                            workTypeNo);

                    statusEnum.setMessage("您还未创建工作计划，是否立即发起任务？");
                    statusEnum.setShowClose(true);
                } else {
                    // 有工作计划
                    String planNo = serverDetail == null ? "" : serverDetail.getPlanNo();
                    String recordId = "";
                    if (serverDetail != null) {
                        recordId = serverDetail.getWtDetail() == null ?
                                "" : serverDetail.getWtDetail().getRecordId();
                    }

                    url = getTicketUrl(
                            context,
                            appNo,
                            appCode,
                            eomOrderSrc,
                            workTypeNo,
                            planNo,
                            recordId,
                            resultDetail.getWorkTicketState());

                    // 无工作票记录
                    if (TextUtils.isEmpty(recordId)) {
                        statusEnum.setMessage("您还未申请工作票，是否立即申请工作票？");
                        statusEnum.setShowClose(true);
                    } else {
                        // 有工作票记录
                        // 工作票是带签发和间断
                        if (TICKET_STATE_WAIT_SIGN.equals(resultDetail.getWorkTicketState())
                                || TICKET_STATE_BREAK.equals(resultDetail.getWorkTicketState())) {
                            // 是待签发时修改签发提示语
                            if (TICKET_STATE_WAIT_SIGN.equals(resultDetail.getWorkTicketState())) {
                                //当前工作票状态是待签发且当前登录人是签发人时可跳转
                                if (isSignPerson) {
                                    statusEnum.setMessage("您的工作票还未签发，是否立即签发工作票？");
                                    statusEnum.setShowClose(true);
                                } else {
                                    // 有签发人
                                    if (!TextUtils.isEmpty(signPerson)) {
                                        StringBuilder wtStr = new StringBuilder();
                                        if (serverDetail != null
                                                && serverDetail.getWtDetail() != null
                                                && !TextUtils.isEmpty(serverDetail.getWtDetail().getWtNo())
                                        ) {
                                            wtStr.append("（编号：")
                                                    .append(serverDetail.getWtDetail().getWtNo())
                                                    .append("）");
                                        }

                                        statusEnum.setMessage("您的工作票还未签发" + wtStr.toString() + "，请联系" + signPerson + "进行签发！");
                                    } else {
                                        // 无签发人
                                        statusEnum.setMessage("您的工作票还未签发！");
                                    }
                                    statusEnum.setShowClose(false);
                                }
                            }
                        }
                    }
                }
                showDialog(context, statusEnum, url);
            } else {
                // 无工单
                showErrorDialog(context, "未查询到此工单！");
            }
        }
    }

    /**
     * 班前会处理逻辑
     *
     * @param context          上下文
     * @param appNo            工作编号
     * @param appCode          业务应用编码
     * @param eomOrderSrc      工单来源系统编号
     * @param workTypeNo       工单类型编号
     * @param result           服务器返回结果
     * @param completeListener 处理结果回调
     */
    private void handleMeeting(
            Context context,
            String appNo,
            String appCode,
            String eomOrderSrc,
            String workTypeNo,
            String result,
            CompleteListener completeListener
    ) {
        // 返回给调用端的值
        MeetingResult meetingResult;
        MeetingResult.VerifyDetail resultDetail;
        MeetingVerify.VerifyDetail serverDetail;

        // 解析服务器返回数据
        MeetingVerify meetingVerify =
                ToolGson2.getBean(result, MeetingVerify.class);
        // 判断班前会状态标志位
        int meetingFlag;
        // 记录工作负责人姓名
        StringBuilder sbMaster = new StringBuilder();
        //计划工单类型
        String mWorkTypeNo = null;
        String ticketRecordId = null;
        if (meetingVerify != null) {
            if (meetingVerify.isSuccess()) {
                serverDetail = meetingVerify.getDTS();
                if (serverDetail != null) {
                    mWorkTypeNo = serverDetail.getWorkTypeNo();
                    // 判断班前会状态
                    List<MeetingVerify.VerifyData> meetings = serverDetail.getSiteMeetings();
                    if (meetings != null && meetings.size() > 0) {
                        String userCode = SharepreferenceUtil.getUserCode(context);
                        if (userCode != null) {
                            // 是否是班组负责人
                            boolean isMaster = false;
                            // 班前会是否召开
                            boolean isMeetingDone = false;

                            for (MeetingVerify.VerifyData item : meetings) {
                                ticketRecordId = item.getWtId();
                                if (MeetingVerify.MEETING_FINISH.equals(item.getIsMeeting())) {
                                    isMeetingDone = true;
                                    break;
                                }

                                // 判断当前账号是否是工作负责人
                                if (userCode.equals(item.getWtHeadId().toUpperCase())) {
                                    isMaster = true;
                                } else {
                                    // 记录工作负责人姓名
                                    if (item.getWtPerson().toUpperCase().contains(userCode)) {
                                        sbMaster.append(" ").append(item.getWtHeadName()).append(" ");
                                    }
                                }
                            }
                            if (isMeetingDone) {
                                meetingFlag = MEETING_HAVE_FINISHED; //已开过班前会
                            } else {
                                if (isMaster) {
                                    meetingFlag = MEETING_NOT_FINISHED_IS_MASTER; //负责人未开班前会
                                } else {
                                    meetingFlag = MEETING_NOT_FINISHED_NOT_MASTER; //成员未开班前会
                                }
                            }
                        } else {
                            meetingFlag = MEETING_NO_DATA; //无班前会信息
                        }
                    } else {
                        meetingFlag = MEETING_NO_DATA; //无班前会信息
                    }
                } else {
                    meetingFlag = MEETING_NO_POWER; //不是班前会成员
                }
            } else {
                // 服务端请求失败
                meetingResult = new MeetingResult("30", "请检查网络状态后尝试");
                completeListener.complete(1, ToolGson2.getJsonStr(meetingResult));
                return;
            }
        } else {
            // 数据解析失败
            meetingResult = new MeetingResult("50", "数据解析异常");
            completeListener.complete(1, ToolGson2.getJsonStr(meetingResult));
            return;
        }

        if (meetingFlag == MEETING_HAVE_FINISHED) {
            // 从本地数据库查询工作票状态
            String state = mTicketDao.findTicketStateByAppNo(
                    appNo,
                    appCode,
                    eomOrderSrc,
                    workTypeNo);

            meetingResult = new MeetingResult("1", "成功");
            resultDetail = new MeetingResult.VerifyDetail(true, true, state);
            meetingResult.setDTS(resultDetail);
            completeListener.complete(1, ToolGson2.getJsonStr(meetingResult));
        } else {
            // 从本地数据库查询工作票状态
            TicketStatePlan ticketPlan = mTicketDao.findTicketPlanByAppNo(
                    appNo,
                    appCode,
                    eomOrderSrc,
                    workTypeNo);

            TicketState ticketState = ticketPlan != null ? ticketPlan.getWtDetail() : null;

            if (TextUtils.isEmpty(ticketRecordId)) {
                if (ticketState != null && !TextUtils.isEmpty(ticketState.getRecordId())) {
                    ticketRecordId = ticketState.getRecordId();
                }
            }

            VerifyStatusEnum statusEnum = VerifyStatusEnum.MEETING_NOT_RAISE;
            switch (meetingFlag) {
                case MEETING_NO_POWER:
                case MEETING_NO_DATA:
                    statusEnum.setMessage("您不在该班前会组中，无权限查看该班前会信息");
                    statusEnum.setShowClose(false);
                    showDialog(context, statusEnum, "");
                    break;
                case MEETING_NOT_FINISHED_IS_MASTER:
                    String url = getMeetingUrl(
                            context,
                            appNo,
                            ticketRecordId,
                            appCode,
                            eomOrderSrc,
                            mWorkTypeNo);

                    statusEnum.setMessage("您还未召开班前会，是否立即召开班前会？");
                    statusEnum.setShowClose(true);
                    showDialog(context, statusEnum, url);
                    break;
                case MEETING_NOT_FINISHED_NOT_MASTER:
                    statusEnum.setMessage("请联系负责人" + sbMaster.toString() + "召开班前会");
                    statusEnum.setShowClose(false);
                    showDialog(context, statusEnum, "");
                    break;
            }
        }
    }

    /**
     * 本地判断风险点验收情况（新）
     *
     * @param context          上下文
     * @param appNo            业务应用工单号
     * @param params           业务应用传入参数
     * @param completeListener 处理结果回调
     */
    private void handleNewRisk(
            Context context,
            String appNo,
            VerifyParams params,
            CompleteListener completeListener
    ) {
        boolean allChecked;

        // 获取工作计划关系表
        AppNoForPlan planData = new AppNoForPlanImpl()
                .getDataByAppNoWithPlanNo(
                        appNo,
                        params.getPlanDetNo(),
                        params.getAppCode(),
                        params.getEomOrderSrc(),
                        params.getWorkTypeNo());

        if (planData != null
                && planData.getRiskRequire() != null
                && "0".equals(planData.getRiskRequire())) {
            allChecked = true;
        } else {
            List<String> idsList = new ArrayList<>();

            TicketMeasureResult data = new KnowledgeCheck().getTicketRiskEvidenceList(
                    appNo,
                    params.getAppCode(),
                    params.getEomOrderSrc(),
                    params.getWorkTypeNo(),
                    params.getPlanDetNo(),
                    params.getIsFilter(),
                    params.getIsShowAppend(),
                    params.getStepNo()
            );

            if (data.getCustom().size() > 0) {
                for (TicketMeasureRisk item : data.getCustom())
                    idsList.add(item.getRecordId());
            }

            if (data.getKnowledge().size() > 0) {
                for (TicketMeasureProcess process : data.getKnowledge())
                    for (TicketMeasureStep step : process.getWorkSteps())
                        for (TicketMeasureRisk rist : step.getMeasures())
                            idsList.add(rist.getRecordId());
            }

            List<TicketMeasureSave> list = new KnowledgeCheck()
                    .getTicketRiskSaveList(
                            appNo,
                            params.getAppCode(),
                            params.getEomOrderSrc(),
                            params.getWorkTypeNo(),
                            params.getPlanDetNo());

            allChecked = true;
            if (list != null
                    && list.size() > 0
                    && idsList.size() > 0) {
                for (TicketMeasureSave item : list) {
                    if (idsList.contains(item.getRecordId())
                            && "0".equals(item.getWtStatus())) {
                        allChecked = false;
                        break;
                    }
                }
            } else
                allChecked = false;
        }

        //返回给调用端的值
        RiskResult.VerifyDetail resultDetail;
        RiskResult riskResult = new RiskResult("1", "成功");

        if (allChecked) {
            // 检查通过
            resultDetail = new RiskResult.VerifyDetail(true, true, "");
            riskResult.setDTS(resultDetail);
            completeListener.complete(1, ToolGson2.getJsonStr(riskResult));
        } else {
            resultDetail = new RiskResult.VerifyDetail(false, false, "");
            riskResult.setDTS(resultDetail);
            completeListener.complete(1, ToolGson2.getJsonStr(riskResult));

            // 未检查通过时显示对话框
            String url = getKeyRiskPointUrl(
                    context,
                    appNo,
                    params.getAppCode(),
                    params.getEomOrderSrc(),
                    params.getWorkTypeNo(),
                    params.getStepNo(),
                    params.getVoicePlayer(),
                    params.getIsFilter(),
                    params.getIsShowAppend()
            );

            showDialog(context, VerifyStatusEnum.RISK_NOT_CHECK, url);
        }
    }

    /**
     * 终结工作票处理逻辑
     *
     * @param context          上下文
     * @param appNo            工单编号
     * @param appCode          业务应用编码
     * @param eomOrderSrc      工单来源系统编号
     * @param workTypeNo       工单类型编号
     * @param result           服务器返回结果
     * @param completeListener 处理结果回调
     */
    private void handleTicketFinishByPlan(
            Context context,
            String appNo,
            String appCode,
            String eomOrderSrc,
            String workTypeNo,
            String result,
            CompleteListener completeListener
    ) {
        // 返回给调用端的值
        TicketFinishResult ticketFinishResult;
        TicketFinishResult.VerifyDetail resultFinishDetail;
        TicketFinishPlanVerify.VerifyDetail serverDetail;
        // 验证是否通过
        boolean checked = true;
        String wtState = "";//工作票状态
        String recordId = "";//工作票id
        // 解析服务器返回数据
        TicketFinishPlanVerify ticketFinishVerify =
                ToolGson2.getBean(result, TicketFinishPlanVerify.class);

        if (ticketFinishVerify != null) {
            if (ticketFinishVerify.isSuccess()) {
                //服务器返回的详情
                serverDetail = ticketFinishVerify.getDTS();
                ticketFinishResult = new TicketFinishResult("1", "成功");
                if (serverDetail != null) {
                    if (!TextUtils.isEmpty(serverDetail.getWtState())) {
                        wtState = serverDetail.getWtState();
                    }
                    if (!TextUtils.isEmpty(serverDetail.getRecordId())) {
                        recordId = serverDetail.getRecordId();
                    }
                    //是待终结状态
                    if (TICKET_STATE_WAIT_FINISH.equals(serverDetail.getWtState())) {
                        if (serverDetail.getConnectPlanCount() == serverDetail.getClosedPlanCount() + 1) {
                            checked = false;
                        }
                    } else {
                        //不是已终结时返回false
                        if (!TICKET_STATE_HAVE_FINISH.equals(serverDetail.getWtState())) {
                            checked = false;
                        }
                    }
                } else {
                    //无工作票信息
                    checked = false;
                }
            } else {
                if (!TextUtils.isEmpty(ticketFinishVerify.getRT_D())) {
                    //服务端请求失败
                    ticketFinishResult = new TicketFinishResult(ticketFinishVerify.getRT_F(), ticketFinishVerify.getRT_D());
                    completeListener.complete(1, ToolGson2.getJsonStr(ticketFinishResult));
                    showDialog(context, ticketFinishVerify.getRT_D(), "", false);
                } else {
                    //服务端请求失败
                    ticketFinishResult = new TicketFinishResult("30", "请检查网络状态后尝试");
                    completeListener.complete(1, ToolGson2.getJsonStr(ticketFinishResult));
                }
                return;
            }
        } else {
            ticketFinishResult = new TicketFinishResult("50", "数据解析异常");
            completeListener.complete(1, ToolGson2.getJsonStr(ticketFinishResult));
            return;
        }
        resultFinishDetail = new TicketFinishResult.VerifyDetail(checked, wtState);
        ticketFinishResult.setDTS(resultFinishDetail);
        completeListener.complete(1, ToolGson2.getJsonStr(ticketFinishResult));

        // 获取工作计划关系表
        AppNoForPlan planData =
                new AppNoForPlanImpl().getDataByAppNo(
                        appNo,
                        appCode,
                        eomOrderSrc,
                        workTypeNo);

        String planNo = planData != null ? planData.getPlanNo() : "";
        if (TICKET_STATE_WAIT_FINISH.equals(resultFinishDetail.getWorkTicketState())) {
            //待终结时检查通过时才显示对话框
            if (!resultFinishDetail.isChecked()) {
                VerifyStatusEnum statusEnum =
                        VerifyStatusEnum.getById(resultFinishDetail.getWorkTicketState());
                String url = getTicketUrl(
                        context,
                        appNo,
                        appCode,
                        eomOrderSrc,
                        workTypeNo,
                        planNo,
                        recordId,
                        resultFinishDetail.getWorkTicketState()
                );
                showDialog(context, statusEnum, url);
            }
        } else {
            //其他状态未检查通过时显示对话框
            if (!resultFinishDetail.isChecked()) {
                VerifyStatusEnum statusEnum =
                        VerifyStatusEnum.getById(resultFinishDetail.getWorkTicketState());
                String url = getTicketUrl(
                        context,
                        appNo,
                        appCode,
                        eomOrderSrc,
                        workTypeNo,
                        planNo,
                        recordId,
                        resultFinishDetail.getWorkTicketState()
                );
                showDialog(context, statusEnum, url);
            }
        }
    }

    /**
     * 打开提示框
     */
    private void showDialog(Context context, VerifyStatusEnum statusEnum, String url) {
        Intent intent = new Intent(context, SafeTipDialogActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(SAFE_VERITY_MESSAGE, statusEnum.getMessage());
        intent.putExtra(SAFE_VERITY_OPEN_URL, url);
        intent.putExtra(SAFE_VERIFY_SHOW_CANCEL, statusEnum.isShowClose());
        context.startActivity(intent);
    }

    /**
     * 作业前提示框
     */
    @SuppressWarnings("SameParameterValue")
    private void showBeforeDialog(Context context, VerifyParams param, String message) {
        Intent intent = new Intent(context, SafeTipDialogSecondActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(SAFE_VERITY_HINT, message);
        intent.putExtra(MEASURE_APPNO, param.getAppNo());
        intent.putExtra(MEASURE_APPCODE, param.getAppCode());
        intent.putExtra(MEASURE_ORDER, param.getEomOrderSrc());
        intent.putExtra(MEASURE_WORK, param.getWorkTypeNo());
        intent.putExtra(MEASURE_PLANNO, param.getPlanDetNo());
        intent.putExtra(MEASURE_FILTER, param.getIsFilter());
        intent.putExtra(MEASURE_APPEND, param.getIsShowAppend());
        intent.putStringArrayListExtra(MEASURE_STEP, (ArrayList<String>) param.getStepNo());
        context.startActivity(intent);
    }

    /**
     * 打开提示框
     *
     * @param context   上下文
     * @param message   提示信息
     * @param url       跳转url
     * @param showClose 是否显示关闭按钮
     */
    @SuppressWarnings("SameParameterValue")
    private void showDialog(Context context, String message, String url, boolean showClose) {
        Intent intent = new Intent(context, SafeTipDialogActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(SAFE_VERITY_MESSAGE, message);
        intent.putExtra(SAFE_VERITY_OPEN_URL, url);
        intent.putExtra(SAFE_VERIFY_SHOW_CANCEL, showClose);
        context.startActivity(intent);
    }

    /**
     * 打开WebView
     *
     * @param context 上下文
     * @param url     webView打开页面地址
     */
    private void openWebActivity(Context context, String url) {
        Intent intent = new Intent(context, MixWebViewActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(WEB_URL, url);
        context.startActivity(intent);
    }

    /**
     * 获取任务发起跳转路径
     *
     * @param context 上下文
     * @param appNo   工作编号
     * @return 返回工作计划完整url
     */
    private String getTaskUrl(
            Context context,
            String appNo,
            String appCode,
            String eomOrderSrc,
            String workTypeNo
    ) {
        Map<String, String> params = new HashMap<>();
        params.put("workNo", appNo);
        params.put("appCode", appCode);
        params.put("eomOrderSrc", eomOrderSrc);
        params.put("workTypeNo", workTypeNo);
        params.put("view", "02");//标识从安全管控跳转到页面
        String localUrl = context.getResources().getString(R.string.task_page_url);
        String onlineUrl = onlineIP + "/#/pages/renwufaqi/renwufaqi-index";
        return buildUrl(offlineMode ? localUrl : onlineUrl, params);
    }

    /**
     * 获取工作票跳转路径
     *
     * @return 返回工作票完整url
     */
    private String getTicketUrl(
            Context context,
            String appNo,
            String appCode,
            String eomOrderSrc,
            String workTypeNo,
            String planNo,
            String recordId,
            String state
    ) {
        String action;
        switch (state) {
            case TICKET_STATE_WAIT_SUBMIT://待提交
                action = "02";
                break;
            case TICKET_STATE_WAIT_SIGN://待签发
                action = "03";
                break;
            case TICKET_STATE_WAIT_ALLOW://待许可
                action = "04";
                break;
            case TICKET_STATE_WAIT_FINISH://待终结
                action = "05";
                break;
            default:
                action = "01";
                break;
        }
        Map<String, String> params = new HashMap<>();
        params.put("appNo", appNo);
        params.put("appCode", appCode);
        params.put("eomOrderSrc", eomOrderSrc);
        params.put("workTypeNo", workTypeNo);
        if (!TextUtils.isEmpty(planNo)) params.put("planNo", planNo);
        if (!TextUtils.isEmpty(recordId)) params.put("recordId", recordId);

        // 查询工作票编号
        String wtNo = mTicketDao.findWtNoByAppNo(
                appNo,
                appCode,
                eomOrderSrc,
                workTypeNo);

        if (!TextUtils.isEmpty(wtNo)) params.put("wtNo", wtNo);

        params.put("action", action);
        params.put("view", "02");//标识从安全管控跳转到页面
        String localUrl = context.getResources().getString(R.string.ticket_page_url);
        String onlineUrl = onlineIP + "/#/pages/gongzuopiao/gongzuopiao-index";
        return buildUrl(offlineMode ? localUrl : onlineUrl, params);
    }

    /**
     * 获取班前会跳转路径
     *
     * @return 返回班前会完整url
     */
    private String getMeetingUrl(
            Context context,
            String appNo,
            String recordId,
            String appCode,
            String eomOrderSrc,
            String workTypeNo
    ) {
        Map<String, String> params = new HashMap<>();
        params.put("appNo", appNo);
        params.put("appCode", appCode);
        params.put("eomOrderSrc", eomOrderSrc);
        params.put("workTypeNo", workTypeNo);
        if (!TextUtils.isEmpty(recordId)) params.put("recordId", recordId);
        if (!TextUtils.isEmpty(workTypeNo)) params.put("workTypeNo", workTypeNo);

        // 获取工作票编号
        String wtNo = mTicketDao.findWtNoByAppNo(
                appNo,
                appCode,
                eomOrderSrc,
                workTypeNo);

        if (!TextUtils.isEmpty(wtNo)) params.put("wtNo", wtNo);

        params.put("view", "02");//标识从安全管控跳转到页面
        String localUrl = context.getResources().getString(R.string.meeting_page_url);
        String onlineUrl = onlineIP + "/#/pages/banqianhui/banqianhui-index";
        return buildUrl(offlineMode ? localUrl : onlineUrl, params);
    }

    /**
     * 获取关键风险点跳转路径
     *
     * @return 返回关键风险点url
     */
    private String getKeyRiskPointUrl(
            Context context,
            String appNo,
            String appCode,
            String eomOrderSrc,
            String workTypeNo,
            List<String> stepNo,
            String voicePlayer,
            String isFilter,
            String isShowAppend
    ) {
        Map<String, String> params = new HashMap<>();
        params.put("appNo", appNo);
        params.put("appCode", appCode);
        params.put("eomOrderSrc", eomOrderSrc);
        params.put("workTypeNo", workTypeNo);
        params.put("voicePlayer", voicePlayer);
        params.put("isFilter", isFilter);
        params.put("isShowAppend", isShowAppend);
        StringBuilder stepSb = new StringBuilder();
        if (stepNo != null && !stepNo.isEmpty()) {
            for (String item : stepNo) {
                stepSb.append(item).append(",");
            }
            params.put("stepNo", stepSb.substring(0, stepSb.length() - 1));
        }

        // 获取工作票编号
        String wtNo = mTicketDao.findWtNoByAppNo(
                appNo,
                appCode,
                eomOrderSrc,
                workTypeNo);

        if (!TextUtils.isEmpty(wtNo)) params.put("wtNo", wtNo);

        params.put("action", "02");//跳转到详情页
        params.put("view", "02");//标识从安全管控跳转到页面
        String localUrl = context.getResources().getString(R.string.knowledge_page_url);
        String onlineUrl = onlineIP + "/#/pages/zhishiku/zhishiku-index";
        return buildUrl(offlineMode ? localUrl : onlineUrl, params);
    }

    /**
     * 获取步骤及风险点跳转路径(知识库)
     *
     * @param context 上下文
     * @param appNo   业务应用工单号
     * @param procNo  步骤列表
     * @return 返回步骤及风险点完整url
     */
    private String getStepAndRiskUrl(
            Context context,
            String appNo,
            String appCode,
            String eomOrderSrc,
            String workTypeNo,
            List<String> procNo,
            String voicePlayer,
            String isFilter,
            String isShowAppend
    ) {
        Map<String, String> params = new HashMap<>();
        params.put("appNo", appNo);
        params.put("appCode", appCode);
        params.put("eomOrderSrc", eomOrderSrc);
        params.put("workTypeNo", workTypeNo);
        params.put("voicePlayer", voicePlayer);
        params.put("isFilter", isFilter);
        params.put("isShowAppend", isShowAppend);
        StringBuilder procSb = new StringBuilder();
        if (procNo != null && !procNo.isEmpty()) {
            for (String item : procNo) {
                procSb.append(item).append(",");
            }
            params.put("procNo", procSb.substring(0, procSb.length() - 1));
        }

        // 获取工作票编号
        String wtNo = mTicketDao.findWtNoByAppNo(
                appNo,
                appCode,
                eomOrderSrc,
                workTypeNo);

        if (!TextUtils.isEmpty(wtNo)) params.put("wtNo", wtNo);

        params.put("action", "01");//跳转到首页
        params.put("view", "02");//标识从安全管控跳转到页面
        String localUrl = context.getResources().getString(R.string.knowledge_page_url);
        String onlineUrl = onlineIP + "/#/pages/zhishiku/zhishiku-index";
        return buildUrl(offlineMode ? localUrl : onlineUrl, params);
    }

    /**
     * 获取知识库首页跳转路径(本地测试)
     */
    private String getKnowledgeUrl() {
        Map<String, String> params = new HashMap<>();
        String onlineUrl = onlineIP + "/#/pages/zhishiku/zhishiku-index";
        return buildUrl(onlineUrl, params);
    }

    /**
     * 提交标准化作业风险点验收数据
     *
     * @param context  上下文
     * @param appNo    工单号
     * @param planNo   工作计划编号
     * @param wtNo     工作票编号
     * @param measures 防范措施集合
     */
    private void uploadTicketRisk(
            Context context,
            final String appNo,
            final String planNo,
            final String wtNo,
            final String isChk,
            final List<TicketMeasureSave> measures,
            final CompleteListener listener
    ) {
        HttpUtil.saveTicketRiskRecordAsync(
                context,
                appNo,
                planNo,
                wtNo,
                isChk,
                JsonUtils.toJson(measures),
                new HttpCallbackInterface() {
                    @Override
                    public void httpSuccess(String result) {
                        LogUtil.i("数据提交成功！");

                        // 保存防范措施记录
                        new TicketMeasureSaveImpl().insertOnlineList(measures);

                        listener.complete(
                                1,
                                ToolGson2.getJsonStr(
                                        new BaseEntity(
                                                "1",
                                                "提交成功!"
                                        )
                                )
                        );
                    }

                    @Override
                    public void httpFailed(int errorCode, String errorMsg) {
                        LogUtil.e("错误码：" + errorCode + "，错误信息：" + errorMsg);

                        listener.complete(
                                1,
                                ToolGson2.getJsonStr(
                                        new BaseEntity(
                                                "0",
                                                "数据提交失败!"
                                        )
                                )
                        );
                    }
                }
        );
    }

    /**
     * 拼接url
     *
     * @param url    无参数url
     * @param params 要拼接的参数
     * @return 返回拼接后完整url
     */
    private String buildUrl(String url, Map<String, String> params) {
        StringBuilder sb = new StringBuilder();
        sb.append(url).append("?");
        Set<String> keySets = params.keySet();
        for (String key : keySets) {
            sb.append(key).append("=").append(params.get(key)).append("&");
        }
        String visitUrl = sb.substring(0, sb.length() - 1);
        LogUtil.e("访问路径：" + visitUrl);
        return visitUrl;
    }

    /**
     * 请求工作票状态接口
     */
    interface IMeasureCallback {
        void onSuccess();

        void onFailure(String msg);
    }

}